<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="${ctx}/js/jquery.itextclear.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script>

<p>
    <input type="file" placeholder="80x80 jpeg/png format" id="form-upload" size="57.6" style="opacity: 0;"><span class="filename" style="-moz-user-select: none;">支持Excel格式导入，字段名称必须和表格字段名一致 </span>
    <a class="button" id="data_import">导入</a>
</p>


<table class="display" id="example">
    <thead>
    <tr>
        <th>选择</th>
        <th>姓名</th>
        <th>性别</th>
        <th>出生日期</th>
        <th>建议岗位</th>
        <th>居住地</th>
        <th>工作年限</th>
        <th>邮箱</th>
        <th>手机</th>
        <th>学历</th>
        <th>薪资</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.employeeinfoBases==null || #request.employeeinfoBases.size==0">
        <tr class="gradeA">
            <td colspan="11">没有数据</td>
        </tr>
    </s:if>
    <s:iterator value="employeeinfoBases" var="reg" status="sta">
        <s:if test="#sta.even">
            <tr class="gradeA">
        </s:if>
        <s:else>
            <tr class="gradeC">
        </s:else>
        <td><input type="checkbox" name="check_staff" value="${reg.id}"/></td>
        <td><a href="#employee/talent_view.xhtml?id=${reg.id}">${reg.name}</a></td>
        <td>${reg.sex=="0"?"男":"女"}</td>
        <td><s:date name="#reg.birthday" format="yyyy/MM/dd"/></td>
        <td>${reg.suggestDuty}</td>
        <td>${reg.address}</td>
        <td>${reg.workAge}</td>
        <td>${reg.email}</td>
        <td>${reg.handSet}</td>
        <td>
            <s:if test="#reg.certificate==1">小学</s:if>
            <s:elseif test="#reg.certificate==2">中学</s:elseif>
            <s:elseif test="#reg.certificate==3">高中</s:elseif>
            <s:elseif test="#reg.certificate==4">大专</s:elseif>
            <s:elseif test="#reg.certificate==5">本科</s:elseif>
            <s:elseif test="#reg.certificate==6">硕士</s:elseif>
            <s:elseif test="#reg.certificate==7">博士</s:elseif>
            <s:elseif test="#reg.certificate==8">博士后</s:elseif>
            <s:else></s:else>
        </td>
        <td>${reg.compensation}</td>
        </tr>
    </s:iterator>
    </tbody>
</table>
<p>
    <%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp" %>
</p>


<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    $(function(){
        AjaxUpload.init('${ctx}/upload/data-import.xhtml', "data_import", "", "");
    });
    function onUploadSubmit(file, ext) {
        alert("数据导入中,请不要刷新页面!");
    }
    function onUploadComplete(file, response) {
        var d;
        try {
            d = eval("[" + response + "]");
        }
        catch(err) {
            alert("文件上传错误！");
            return;
        }
        //var message = d[0].message;
        //上传出错
        if (d[0].success == false) {
            alert("上传出错")
            return;
        }
        //上传成功
        else {
            var msg = d[0].result;
            if(msg == "file_not_found"){
                alert("文件找不到");
            }else if(msg == "file_is_empty"){
                alert("文件为空");
            }else if(msg == "all_success"){
                alert("数据导入成功");
            }else if(msg > 0){
                alert(msg+"条数据导入成功");
            }
            location.reload();//刷新页面
        }
    }

    function toUrl(url) {
        window.location.href = url;
    }

    //删除员工
    function deleteEmployees() {
        var checkIds = new Array();
        $("input[type='checkbox'][name='check_staff']").each(function() {
            if (this.checked) {
                checkIds.push(this.value);
            }
        });
        if (checkIds.length == 0) {
            return;
        }
        if (confirm("确定要删除选中的数据吗？删除后将无法恢复!")) {
            doDeleteEmps(checkIds.join(","))
        }
    }

    function doDeleteEmps(ids) {
        var url = "${ctx}/employee/talent_delete.xhtml";
        $.ajax(url, {
            type: "POST",
            data:{"empIds":ids},
            dataType:"html",
            cache:false,
            success:function(a) {
                var obj = $("#list_content_" + currentTabOrgId);
                obj.html("");
                obj.append(a);

            },
            complete:function() {

            }
        });

    }

    //选择员工更新
    function updateSelectedEmployees() {
        var checkIds = new Array();
        $("input[type='checkbox'][name='check_staff']").each(function() {
            if (this.checked) {
                checkIds.push(this.value);
            }
        });
        if (checkIds.length == 0) {
            return;
        }

        if (checkIds.length > 1) {
            alert("每次只能更新一个人员信息");
            return;
        }
        var url = "#employee/talent_edit.xhtml?id=" + checkIds[0];
        window.location.href = url;

    }
</script>